using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Portal.WebControls;

namespace Behemoth.SharePoint.WebParts {

  /// <summary>
  /// Overrides the KPIListWebPart to provide a means for getting
  /// an XmlDocument with all the list results for GetCallbackResult.
  /// This may eventually make it possible to expose KpiData as a
  /// web service outside of SharePoint.
  /// </summary>
  [Guid("b637c966-7310-4599-887a-9a151677321e")]
  public class KpiDataWebPart : KPIListWebPart {

		public KpiDataWebPart() : base() { 
			//handlers = new KpiPostBackEventHandlers(this);
		}

		public XmlDocument GetAllKpiData() {
			StringBuilder xml = new StringBuilder();
			xml.Append( "<?xml version=\"1.0\"?>" );
			xml.Append( "<KpiList>" );
			int count = this.KpiList.Items.Count;
			for (int currentId = 1; currentId <= count; currentId++) {
				xml.Append( string.Format( "<KpiListItem ID=\"{0}\">", currentId.ToString() ) );
				this.RaiseCallbackEvent( "ID=" + currentId.ToString() );
				string result = this.GetCallbackResult();
				xml.Append( result );
				xml.Append( "</KpiListItem>" );
			}
			xml.Append( "</KpiList>" );
			XmlDocument kpiXmlData = new XmlDocument();
			kpiXmlData.LoadXml( xml.ToString() );
			return kpiXmlData;
		}

		//protected override void OnPreRender( EventArgs e ) {
		//	base.OnPreRender( e );
		//}

		//private KpiPostBackEventHandlers handlers = new KpiPostBackEventHandlers();

	} // class
} // namespace
